﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DBBase;

namespace Business.系统设置
{
    public partial class FunctionalTable : Form
    {

        public string sjczname;
        public string sjcznumber;
        public FunctionalTable(string jczname,string jcznumber)
        {
            sjczname = jczname;
            sjcznumber = jcznumber;
            InitializeComponent();
        }
        public void getjilu()
        {
            lv.Items.Clear();
            Query quer = new Query();
            string sql = string.Format("select * from FunctionalBlock where ST_name='{0}'", quer.EncodeBase64("utf-8", sjczname));
            DataTable dt = quer.GetTable(sql);
            if (dt.Rows.Count > 0)
            {
                if (dt.Rows.Count > 0)
                {
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        ListViewItem lt = new ListViewItem(string.Format("{0}", i + 1));
                        lt.SubItems.Add(quer.DecodeBase64("utf-8", dt.Rows[i]["ST_name"].ToString().Trim()));
                        lt.SubItems.Add(dt.Rows[i]["ST_number"].ToString().Trim());
                        lt.SubItems.Add(dt.Rows[i]["ST_block"].ToString().Trim());
                        lt.SubItems.Add(dt.Rows[i]["ST_zt"].ToString().Trim().Contains("True") ? "是" : "否");
                        this.lv.Items.Add(lt);
                    }
                }
            }

        }

        private void lv_SelectedIndexChanged(object sender, EventArgs e)
        {
            foreach (ListViewItem item in lv.SelectedItems)
            {
                comboBox2.Text = item.SubItems[3].Text.ToString().Trim();
                comboBox1.Text = item.SubItems[4].Text.ToString().Trim();
            }
        }

        private void skinButton2_Click(object sender, EventArgs e)
        {
            if (comboBox2.Text.Length<1||comboBox1.Text.Length<1)
            {
                MessageBox.Show("业务模块为空或者状态为空");
            }
            Query quer = new Query();
            string sql = "";
            sql = string.Format(@"select * from FunctionalBlock where ST_name='{0}' and ST_number='{1}'and ST_block='{2}'", quer.EncodeBase64("utf-8", sjczname), sjcznumber, comboBox2.Text);
            DataTable dt = quer.GetTable(sql);
            if (dt.Rows.Count > 0)
            {
                sql = string.Format(@"update FunctionalBlock set ST_zt={3} where ST_name='{0}' and ST_number='{1}'and ST_block='{2}'",
               quer.EncodeBase64("utf-8", sjczname), sjcznumber, comboBox2.Text, comboBox1.Text.Contains("是") ? "1" : "0");
                quer.InsertDB(sql);
            }
            else
            {
                sql = string.Format(@"insert into FunctionalBlock (ST_name,ST_number,ST_block,ST_zt) Values
                ('{0}','{1}','{2}',{3})", quer.EncodeBase64("utf-8", sjczname), sjcznumber, comboBox2.Text, comboBox1.Text.Contains("是") ? "1" : "0");
                quer.InsertDB(sql);
            }
            getjilu();
        }

        private void skinButton1_Click(object sender, EventArgs e)
        {
            Query quer = new Query();
            string sql = "";
            sql = string.Format(@"update FunctionalBlock set ST_zt={3} where ST_name='{0}' and ST_number='{1}'and ST_block='{2}'",
                quer.EncodeBase64("utf-8", sjczname), sjcznumber, comboBox2.Text, comboBox1.Text.Contains("是") ? "1" : "0");
            quer.InsertDB(sql);
            getjilu();
        }

        private void skinButton3_Click(object sender, EventArgs e)
        {
            Query quer = new Query();
            string sql = "";
            sql = string.Format(@"delete FunctionalBlock  where ST_name='{0}' and ST_number='{1}'and ST_block='{2}'",
                quer.EncodeBase64("utf-8", sjczname), sjcznumber, comboBox2.Text);
            quer.InsertDB(sql);
            getjilu();
        }

        private void FunctionalTable_Load(object sender, EventArgs e)
        {
            getjilu();
        }
    }
}
